package java8.timeutil;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author Cheng Jun
 * @version 1.0
 * Description: jdk1.8 LocalDateTime API学习
 * 我的博客地址：https://blog.csdn.net/cauchy6317/article/details/99406404
 * @date 2019/8/10 10:04
 */
public class LocalDateTimeStudy {

    public static void main(String[] args) {

        //获取当前日期时间对象：2019-08-13T10:15:20，withNano(0)去掉毫秒数
        LocalDateTime localDateTime = LocalDateTime.now().withNano(0);

        //获取日期对象：2019-08-13
        LocalDate today = LocalDate.now();

        //创建时间对象：10:15:20
        LocalTime now = LocalTime.of(10, 15, 20);

        //创建LocalDateTime对象：2019-08-13T10:15:20
        LocalDateTime dateTime = LocalDateTime.of(today, now);

        //定义日期时间格式：yyyy年MM月dd日HH点mm分ss秒
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH点mm分ss秒");

        //新中国成立的日期时间对象：1949-10-01T14:00
        // LocalDateTime birthdayOfPRC = LocalDateTime.parse("1949年10月01日14点00分00秒", dateTimeFormatter);

        //-999999999-01-01T00:00
        LocalDateTime minDatetime = LocalDateTime.MIN;

        //+999999999-12-31T23:59:59.999999999
        LocalDateTime maxDatetime = LocalDateTime.MAX;

        ZonedDateTime zonedDateTime = ZonedDateTime.now();
        //
        LocalDateTime fromDatetime = LocalDateTime.from(zonedDateTime);

        System.out.println(fromDatetime);
        // dateTime.truncatedTo()

        // LocalDateTime.from();
        //
        // dateTime.

        dateTime.toLocalDate();
        LocalDate today1 = LocalDate.from(dateTime);
        System.out.println(today1);


        LocalDateTime parse = LocalDateTime.parse("2020-04-17T13:25:33");
        System.out.println("LocalDateTime.now().isAfter(parse)" + LocalDateTime.now().isAfter(parse));


        System.out.println(LocalDateTime.ofInstant(Instant.ofEpochSecond(1597816800L), ZoneOffset.systemDefault()));
        LocalDateTime orderCode = LocalDateTime.now();
        System.out.println(orderCode.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
        System.out.println(orderCode);

        // java.util.Date --> java.time.LocalDate
        java.util.Date date = new java.util.Date();
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime localDateTime1 = LocalDateTime.ofInstant(instant, zone);

        LocalDateTime start  = LocalDateTime.parse("2020-04-17T12:00:05");
        LocalDateTime end = LocalDateTime.parse("2020-04-17T13:51:13");
        System.out.println(end.minusMinutes(90).isAfter(start));

        System.out.println(LocalDateTime.now(ZoneOffset.UTC));
        System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
}
